package ncov.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author WuChangJian
 * @date 2020/6/15 19:39
 */
public class BackInterceptor extends MethodFilterInterceptor {
    public static final String BACK_LOGIN = "back_login";
    @Override
    protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession session = request.getSession();
        Object obj = session.getAttribute("localAuth");
        if (obj != null) {
            return actionInvocation.invoke();
        } else {
            return BACK_LOGIN;
        }
    }
}
